package com.reminiscence.classes;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.graphics.Bitmap;
import android.util.Log;

import com.reminiscence.database.OperazioniDB;
import com.reminiscence.main.MainActivity;
import com.reminiscence.utils.Utils;

public class Utente implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public String nome;
	public String cognome;
	public String dataN;
	public String sesso;
	public String titoloStudio;
	public String eMail;
	public String luogoN;
	public String provincia;
	public String residenza;
	public String info;
	public String password;
	public String nomeUtente;
	public String statoCivile;
	public String profPrinc;
	public String profAt;
	public String immagine;
	public Integer login;
	public Integer online;
	public String deviceID;
	public String descrizioneFoto;
	public Bitmap bitmap;
	
	private ArrayList<NameValuePair> params;
	
	public Boolean registrazione(Activity activity)
	{
		Boolean ret = false;
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("IdUtente", this.nomeUtente));
        params.add(new BasicNameValuePair("Nome", this.nome));
        params.add(new BasicNameValuePair("Cognome", this.cognome));
        params.add(new BasicNameValuePair("Sesso", this.sesso));
        params.add(new BasicNameValuePair("DataNascita", this.dataN.toString()));
        params.add(new BasicNameValuePair("LuogoNascita", this.luogoN));
        params.add(new BasicNameValuePair("Provincia", this.provincia));
        params.add(new BasicNameValuePair("EMail", this.eMail));
        params.add(new BasicNameValuePair("SitSentimentale", this.statoCivile));
        params.add(new BasicNameValuePair("Password", this.password));
        
               
        Log.i("utente: ", this.nomeUtente);
        
        try
		{
			ret =  (Boolean)(new OperazioniDB(activity, "registrazione", params).execute().get());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
		return ret;
	}
	
	public Boolean logIn(Activity activity)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("IdUtente", this.nomeUtente));
		params.add(new BasicNameValuePair("Password", this.password));
		try
		{
			ret =  (Boolean)(new OperazioniDB(activity, "login", params).execute().get());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return ret;
	}
	
	public Boolean logOut(Activity activity)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("IdUtente", this.nomeUtente));
		try
		{
			ret =  (Boolean)(new OperazioniDB(activity, "logout", params).execute().get());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return ret;
	}
	
	public Boolean updateProfilo(Activity activity)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("IdUtente", this.nomeUtente));
		params.add(new BasicNameValuePair("FotoProfilo", this.immagine));
		return ret;
	}
	
	public Boolean leggiUtente(Activity activity)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("IdUtente", this.nomeUtente));
		
		try
		{
			ret =  (Boolean)(new OperazioniDB(activity, "leggiUtente", params).execute().get());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return ret;
	}
	
	public Boolean leggiUtenteA(Activity activity)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("IdUtente", this.nomeUtente));
		
		try
		{
			ret =  (Boolean)(new OperazioniDB(activity, "leggiAmico", params).execute().get());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return ret;
	}
	
	public Boolean aggiornaProfilo(Activity activity)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("IdUtente", this.nomeUtente));
		params.add(new BasicNameValuePair("Info", this.info));
		params.add(new BasicNameValuePair("TitoloStudio", this.titoloStudio));
		params.add(new BasicNameValuePair("Residenza", this.residenza));
		params.add(new BasicNameValuePair("ProfPrinc", this.profPrinc));
		params.add(new BasicNameValuePair("ProfAt", this.profAt));
		params.add(new BasicNameValuePair("FotoProfilo", this.immagine));
		try
		{
			ret =  (Boolean)(new OperazioniDB(activity, "aggiornaProfilo", params).execute().get());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return ret;
		
	}
	
	public Boolean modificaProfilo(Activity activity)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("IdUtente", this.nomeUtente));
		params.add(new BasicNameValuePair("Info", this.info));
		params.add(new BasicNameValuePair("SitSentimentale", this.statoCivile));
		params.add(new BasicNameValuePair("EMail", this.eMail));
		params.add(new BasicNameValuePair("Residenza", this.residenza));
		params.add(new BasicNameValuePair("TitoloStudio", this.titoloStudio));
		params.add(new BasicNameValuePair("ProfPrinc", this.profPrinc));
		params.add(new BasicNameValuePair("ProfAt", this.profAt));
		
		try
		{
			ret = (Boolean)(new OperazioniDB(activity, "modificaProfilo", params).execute().get());
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
		return ret;
	}
	
	public Boolean cercaUtente(Activity activity)
	{
		Boolean ret = false;
		
		ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
		
		if(!this.nome.equals("") && !this.cognome.equals("") && !this.dataN.equals("") && !this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Nome", this.nome));
			params.add(new BasicNameValuePair("Cognome", this.cognome));
			params.add(new BasicNameValuePair("DataNascita", this.dataN));
			params.add(new BasicNameValuePair("LuogoNascita", this.luogoN));
			
		}else if(!this.nome.equals("") && this.cognome.equals("") && this.dataN.equals("") && this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Nome", this.nome));
			
		}else if(this.nome.equals("") && !this.cognome.equals("") && this.dataN.equals("") && this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Cognome", this.cognome));
			
		}else if(this.nome.equals("") && this.cognome.equals("") && !this.dataN.equals("") && this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("DataNascita", this.dataN));
			
		}else if(this.nome.equals("") && this.cognome.equals("") && this.dataN.equals("") && !this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("LuogoNascita", this.luogoN));
			
		}else if(!this.nome.equals("") && !this.cognome.equals("") && this.dataN.equals("") && this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Nome", this.nome));
			params.add(new BasicNameValuePair("Cognome", this.cognome));
			
		}else if(!this.nome.equals("") && this.cognome.equals("") && !this.dataN.equals("") && this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Nome", this.nome));
			params.add(new BasicNameValuePair("DataNascita", this.dataN));
			
		}else if(!this.nome.equals("") && this.cognome.equals("") && this.dataN.equals("") && !this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Nome", this.nome));
			params.add(new BasicNameValuePair("LuogoNascita", this.luogoN));
			
		}else if(this.nome.equals("") && !this.cognome.equals("") && !this.dataN.equals("") && this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Cognome", this.cognome));
			params.add(new BasicNameValuePair("DataNascita", this.dataN));
			
		}else if(this.nome.equals("") && !this.cognome.equals("") && this.dataN.equals("") && !this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Cognome", this.cognome));
			params.add(new BasicNameValuePair("LuogoNascita", this.luogoN));
			
		}else if(this.nome.equals("") && this.cognome.equals("") && !this.dataN.equals("") && !this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("DataNascita", this.dataN));
			params.add(new BasicNameValuePair("LuogoNascita", this.luogoN));
			
		}else if(!this.nome.equals("") && !this.cognome.equals("") && !this.dataN.equals("") && this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Nome", this.nome));
			params.add(new BasicNameValuePair("Cognome", this.cognome));
			params.add(new BasicNameValuePair("DataNascita", this.dataN));
			
		}else if(!this.nome.equals("") && !this.cognome.equals("") && this.dataN.equals("") && !this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Nome", this.nome));
			params.add(new BasicNameValuePair("Cognome", this.cognome));
			params.add(new BasicNameValuePair("LuogoNascita", this.luogoN));
			
		}else if(this.nome.equals("") && !this.cognome.equals("") && !this.dataN.equals("") && !this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Cognome", this.cognome));
			params.add(new BasicNameValuePair("DataNascita", this.dataN));
			params.add(new BasicNameValuePair("LuogoNascita", this.luogoN));
			
		}else if(!this.nome.equals("") && this.cognome.equals("") && !this.dataN.equals("") && !this.luogoN.equals("")){
			
			params.add(new BasicNameValuePair("Nome", this.nome));
			params.add(new BasicNameValuePair("DataNascita", this.dataN));
			params.add(new BasicNameValuePair("LuogoNascita", this.luogoN));
			
		}
		
		try
		{
			ret = (Boolean)(new OperazioniDB(activity, "ricercaUtenti", params).execute().get());
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
		return ret;
	}
}
